package com.git.controller;

import com.git.bean.Users;
import com.git.service.HouseService;
import com.git.service.UserService;
import org.apache.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author 高源蔚
 * @date 2021/12/23-10:22
 * @describe
 */
@Controller
@RequestMapping("/user")
public class UserController {

    private Logger logger = LoggerFactory.getLogger(UserController.class);

    @Reference(url = "dubbo://localhost:20880")
    private UserService userService;

    @RequestMapping("regs")
    public String regsUser(Users users){
        logger.info("注册功能",users);
        try {
            userService.addUser(users);
            return "login";
        }catch (Exception e){
            logger.error("注册功能失败",e);
        }
        return "erro";
    }


    @RequestMapping("/login")
    public String login(Users user){
        try {
            logger.info(user+"进入了登录");
            Users loginUser = userService.findUserById(user.getId());
            System.out.println(loginUser);
            if(user.getPassword().equals(loginUser.getPassword())){
                System.out.println("登陆成功");
                return "redirect:/house/toList";
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("登录异常");
        }
        return "/login.html";
    }


}
